﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
<title></title>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
	<section class="content-header">
		<h1><spring:message code="message.lable.drugcatalogSTDaddDetail"/></h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.StdManage"/></a></li>
            <li class="active"><a href="#"><spring:message code="message.lable.drugcatalogStd"/></a></li>
		</ol>
	</section>
	<section class="content">
		<div class=" box box-success">
			<div class="box-body">
			<form action="" id="form">
			
			      <div class="input">
                           <div class="textalign1"><spring:message code="message.listForm.tongYongMing"/>：</div>
                            <div class="boxinput">
                                <input type="text" class="textinput" id="qualityspecName" name="qualityspecName" placeholder="<spring:message code="message.listForm.tongYongMing"/>"/>
                            </div>
                          
                          <div class="textalign"><spring:message code="message.listForm.yaoPinBianMa"/>：</div>
                            <div class="boxinput">
                                <input type="text" class="textinput" id="qualityspecCode" name="qualityspecCode" placeholder="<spring:message code="message.listForm.yaoPinBianMa"/>"/>
                            </div>
                         
                          <div class="textalign">
                                 <input type="button" id="selectDicCompType" onclick="likeQuery();" class="btn btn-success btn-sm" value="<spring:message code="message.button.seachSpacing"/>">
                          </div>
                           
                    </div> 
                    
                </form>
            </div>
        </div>
         <input id="drugcatalogId" value="${drugcatalogId}" style="display: none;" />
         <input id="drugcatalogName" value="${Name}" style="display: none;"  />
		<table class="jqgrid" id="gridlist"></table>
		<div id="gridpage"></div>
		<div class=" box box-warning bottongroup">
			<a href="${ctx }/stdDrugcatalog/toStdDrugcatalogDetailInfo.html?drugcatalogId=${drugcatalogId}&drugcatalogName=${Name}" class="btn btn-default btn-sm" ><spring:message code="message.button.seeDetail"/></a>
			<a href="${ctx }/stdDrugcatalog/list.html"  class="btn btn-default btn-sm"><spring:message code="message.button.getBackSpacing"/></a>
		</div>
		      <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
            	<div class="modal-content">
                	<div class="modal-header bg-primary">
                    	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    	<h5 class="modal-title" id="exampleModalLabel"><spring:message code="message.jqGrid.cz.add"/><spring:message code="message.listForm.yaoPin"/></h5>
                    </div>
                    <form action="" id="form">
                    <div class="modal-body">
                    
                    	<div class="form-group form-group-xs">
							<label for="recipient-name" class="control-label"><spring:message code="message.listForm.yaoPin"/><spring:message code="message.listForm.mingCheng"/>：</label>
							<div class="">
                            	<input type="text" class="form-control" id="drugName"  readonly="readonly">
                        	</div>
                    	</div>
                    	
                    	<div class="form-group form-group-xs">
							<label for="recipient-name" class="control-label"><spring:message code="message.listForm.fenLeiMingCheng"/>：</label>
							<div class="">
                            	<input type="text" class="form-control" id="qualityspecClass"  placeholder="<spring:message code="message.listForm.fenLeiMingCheng"/>">
                        	</div>
                    	</div>
                    	
                    	<div class="form-group form-group-xs">
							<label for="recipient-name" class="control-label"><spring:message code="message.listForm.pinZhongXuHao"/>：</label>
							<div class="">
                            	<input type="text" class="form-control" id="qualityspecIndex"  placeholder="<spring:message code="message.listForm.pinZhongXuHao"/>">
                        	</div>
                    	</div>
                    	
                    	<div class="form-group form-group-xs">
							<label for="recipient-name" class="control-label"><spring:message code="message.lable.remark"/>：</label>
							<div class="">
                            	<textarea class="form-control" rows="" placeholder="<spring:message code="message.lable.remark"/>" id="remark" cols=""></textarea>
                        	</div>
                    	</div>
                    	
                       <input type="text" id="qualityspecId" name="qualityspecId" style="display:none" />
						<div id="twoSpec" style="display:none"></div>
					</div>
					</form>
                    <div class="modal-footer">
                     <input hidden="true" id="spid"/>
           			   <input hidden="true" id="spfatherid"/>
                        <button type="button" class="btn btn-primary btn-sm"  onclick="save();"><spring:message code="message.button.saveSpacing"/></button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType"><spring:message code="message.button.closeSpacing"/></button>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //绑定回车
    $('#qualityspecCode,#qualityspecName').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectDicCompType').click();
        }
    }); 
  
    $("#qualityspecName").focus();//加载页面光标在第一个查询框内
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getStdDrugcatalogDetailInfoAdd.html?drugcatalogId=${drugcatalogId}&drugcatalogName=${drugcatalogName}",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                height: 270,                   	
                colNames: ['<spring:message code="message.jqGrid.cz"/>',
                           '<spring:message code="message.listForm.yaoPin"/>id',
                           '<spring:message code="message.listForm.yaoPinBianMa"/>',
                           '<spring:message code="message.listForm.tongYongMing"/>',
                           '<spring:message code="message.listForm.jiXing"/>',
                           '<spring:message code="message.listForm.guiGe"/>'
                           ],
                colModel: [
						{ name: 'operate', width: "7%",align: 'center',sortable: false,
							formatter : function(val, opts, rowdata) {
								var str =  "<a href=\"javascript:toAdd('"+rowdata.qualityspecId+"','"+rowdata.qualityspecName+"');\" style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat 0px -80px' class='opIcon' title='<spring:message code="message.jqGrid.cz.add"/>'></a>";
								return str;
							}
						},
						{ name: 'qualityspecId',hidden:true, width: "0%",align: 'center',sortable: false},		
						{ name: 'qualityspecCode', width: "20%",align: 'center',sortable: false},
						{ name: 'qualityspecName', width: "20%",align: 'center' ,sortable: false},
						{ name: 'formName', width: "20%",align: 'center',sortable: false},
						{ name: 'specName', width: "20%",align: 'center',sortable: false}
						
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                viewrecords: true,
               // scroll: true,//下拉刷新
                caption: "<spring:message code="message.list.drugqualityspecStdlist"/>",
                jsonReader: {
                	repeatitems: false,
                	id: "compRegId"
                },
                gridComplete: function(){
                	var page = $("#gridlist").jqGrid('getGridParam','page');
            		var rows = $('#gridlist').getGridParam("rowNum");
            		var maxnum = (rows*page).toString();
            		var len = (maxnum.length)*10;
            		$('.jqgfirstrow').find('td').eq(0).css('width',len+'px');
                	$('#gridlist_rn').css('width',len+'px');
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        
        function likeQuery(){
        	var data = formatForm("form");
	       	$("#gridlist").jqGrid('setGridParam', {
	       		mtype:"post",
	       		postData:data,
	       	    page: 1 
	       }).trigger("reloadGrid");
       }
        
        function toAdd(qualityspecId,drugName){
        	$('#qualityspecClass').val("");
        	$('#qualityspecIndex').val("");
        	$('#remark').val("");
        	$('#drugName').val(drugName);
	         $('#qualityspecId').val(qualityspecId);
         	 $('#exampleModal').modal({
                 keyboard: true
             })
        }
        function validate() {
       		var qualityspecClass = $.trim($("#qualityspecClass").val());
       		if (qualityspecClass.length>512) {
       			$.HN.message.alert("<spring:message code="message.listForm.fenLeiMingCheng"/><spring:message code="message.info.zuiDaChangDu"/>512<spring:message code="message.info.geZiFu"/>！", " ", "info");
       			return false;
       		}
       		
       		var qualityspecIndex = $.trim($("#qualityspecIndex").val());
       		if (isNaN(qualityspecIndex)) {
       			$.HN.message.alert("<spring:message code="message.listForm.pinZhongXuHao"/><spring:message code="message.yanZheng.zhiNengYouZiMuShuZiZuCheng"/>", " ", "info");
       			return false;
       		}
       		if (qualityspecIndex.length>4) {
       			$.HN.message.alert("<spring:message code="message.listForm.pinZhongXuHao"/><spring:message code="message.info.zuiDaChangDu"/>4<spring:message code="message.info.geZiFu"/>！", " ", "info");
       			return false;
       		}
       		
       		var remark = $.trim($("#remark").val());
       		if (remark.length>2000) {
       			$.HN.message.alert("<spring:message code="message.lable.remark"/><spring:message code="message.info.zuiDaChangDu"/>2000<spring:message code="message.info.geZiFu"/>！", " ", "info");
       			return false;
       		}
       		return true;
        }
        function save() {
        	if(validate()){
               	var drugcatalogId = $("#drugcatalogId").val();//药品目录
               	var qualityspecId = $("#qualityspecId").val();//药品ID
               	var qualityspecIndex = $("#qualityspecIndex").val();//品种序号
               	var qualityspecClass = $("#qualityspecClass").val();//分类名称
               	var remark = $("#remark").val();//备注
               	var data = {
               			"drugcatalogId":drugcatalogId,
               			"qualityspecId":qualityspecId,
               			"qualityspecIndexStr":qualityspecIndex,
               			"qualityspecClass":qualityspecClass,
               			"remark":remark
               	}
	            $.post("${ctx}/stdDrugcatalog/addStdDrugcatalogDetailInfo.html",data, function(result) {
	                if (result.success) {
	                    $.HN.message.alert("<spring:message code="message.jqGrid.cz.add"/><spring:message code="message.HN.alert.chengGong"/>！", " ", "success");
	                    $("#gridlist").jqGrid('setGridParam', {
   	    	              page: 1
   	    	          }).trigger("reloadGrid");
   	    	          $('#exampleModal').modal('hide');
	                } else {
	                    $.HN.message.alert("<spring:message code="message.jqGrid.cz.add"/><spring:message code="message.HN.alert.shibai"/>！", " ", "error");
	                }
	            }, "json");
       		 }
        }
        
        
    </script>
</body>
</html>